import { baseRequestClient } from './request';

/** 商品项 */
export interface ProductItem {
  id: string | number;
  name: string;
  category: string;
  singlePrice: number;
  boxPrice: number;
  recyclePrice: number;
  // 可按后端实际字段继续扩展
}

/** 商品列表响应 */
export interface ProductListRes {
  code: number;
  data: ProductItem[];
  message: string;
  status: boolean;
  success: boolean;
  timestamp: number;
}

/**
 * 获取商品列表（GET /product/list）
 */
export async function getProductList() {
  const res = await baseRequestClient.get<ProductListRes>('/product/list');
  return res?.data;
}

/** 新增商品入参 */
export interface AddProductPayload {
  firstCategory: string;
  secondCategory: string;
  name: string;
  singleBottleSellingPrice: number;
  originalBoxSellingPrice: number;
  singleBottleRecyclingPrice: number;
  originalBoxRecyclingPrice: number;
  status: number;
  image: string[];
}

/**
 * 新增商品（POST /product/add）
 */
export async function addProduct(payload: AddProductPayload) {
  const res = await baseRequestClient.post('/product/add', payload);
  return res?.data;
}

/** 更新商品入参 */
export interface UpdateProductPayload extends AddProductPayload {
  id: string;
}

/**
 * 更新商品（POST /product/update）
 */
export async function updateProduct(payload: UpdateProductPayload) {
  const res = await baseRequestClient.post('/product/update', payload);
  return res?.data;
}

/**
 * 删除商品（DELETE /product/{id}）
 */
export async function deleteProduct(id: string) {
  const res = await baseRequestClient.delete(`/product/${id}`);
  return res?.data;
}